package cn.itcast.algorithm.exercise;

import org.junit.Test;

import java.util.Arrays;

/**
 * create by zhangtian105 on 2022/5/23
 */
public class ExerciseAB30 {
    @Test
    public void exerciseAB30Test() {
        int[] arr = new int[]{5,2,3,1,4} ;
        Arrays.stream(MySort(arr)).forEach(t-> System.out.print(t + " "));
        System.out.println();
    }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     * 将给定数组排序
     * @param arr int整型一维数组 待排序的数组
     * @return int整型一维数组
     */
    public int[] MySort (int[] arr) {
        // write code here
        if (arr == null || arr.length <= 1) {
            return arr ;
        }

        int length = arr.length ;
        for (int i = 0; i < length; i++) {
            int min = arr[i] ;
            for (int j = i + 1; j < length ; j++){
                if (min > arr[j]) {
                    min = arr[j] ;
                    arr[j] = arr[i] ;
                    arr[i] = min ;
                }
            }
        }

        return arr ;
    }
}
